package com.lupus.util;

import java.io.*;
import javax.servlet.http.HttpServletRequest;

public class StreamUtil {
	public static String getContent(HttpServletRequest request){
		try{
			return getContent(request.getInputStream(),request.getContentLength());
		}catch(IOException e){
			throw new RuntimeException(e);
		}
	}
	
	public static String getContent(InputStream is,int paragraphLength){
		try{
			byte[] byteArray = new byte[paragraphLength];
			int length = 0,i = 0;
			while(i>-1){
				length+=i;
				i=is.read(byteArray);
			}
			return new String(byteArray,0,length,"UTF-8");
		}catch(IOException e){
			throw new RuntimeException(e);
		}finally{
			if(is!=null){
				try {
					is.close();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
	}
}
